//
//  TERotateViewController.m
//  TintExample
//
//  Created by Kevin Wu on 4/23/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import "TERotateViewController.h"

@implementation TERotateViewController


#pragma mark - UIViewController

- (void)loadView {
    [super loadView];
    
    _container = [[UIView alloc] init];
    _container.frame = TTRectMake(50.0, 150.0, 200.0, 200.0);
    _container.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:_container];
    
    _button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_container addSubview:_button];
    _button.normalTitle = @"TITTLE";
    _button.size = TTSizeSquare(100.0);
    [_button moveToCenterOfSuperview];
    
    [self addButtonWithTitle:@"Rotate left" selector:@selector(rotateLeft:)];
    [self addButtonWithTitle:@"Rotate right" selector:@selector(rotateRight:)];
    
    [self addButtonWithTitle:@"Move left top" selector:@selector(moveToLeftTop:)];
    [self addButtonWithTitle:@"Move right bottom" selector:@selector(moveToRightBottom:)];
    
    [self addButtonWithTitle:@"Move container left top" selector:@selector(moveContainerToLeftTop:)];
    [self addButtonWithTitle:@"Move container right bottom" selector:@selector(moveContainerToRightBottom:)];
}

- (void)viewDidLoad {
    [super viewDidLoad];
}



- (void)rotateLeft:(id)sender {
    
    CGAffineTransform transform = CGAffineTransformRotate(_container.transform, -(M_PI/8.0));
    _container.transform = transform;
}

- (void)rotateRight:(id)sender {
    CGAffineTransform transform = CGAffineTransformRotate(_container.transform, (M_PI/8.0));
    _container.transform = transform;
}



- (void)moveToLeftTop:(id)sender {
    _button.center = TTPointMake(_button.center.x-5, _button.center.y-5);
}

- (void)moveToRightBottom:(id)sender {
    _button.center = TTPointMake(_button.center.x+5, _button.center.y+5);
}


- (void)moveContainerToLeftTop:(id)sender {
    _container.center = TTPointMake(_container.center.x-5, _container.center.y-5);
}

- (void)moveContainerToRightBottom:(id)sender {
    _container.center = TTPointMake(_container.center.x+5, _container.center.y+5);
}


@end
